const Koa = require('koa');

const app = new Koa();

//koa-static  处理静态资源

const static = require('koa-static');

const path = require('path');

app.use(static(path.join(__dirname,'./public/')));

//koa-bodyparser 把前端传递的参数放到ctx.request.body

const bodyparser = require('koa-bodyparser');

app.use(bodyparser());

//koa-router  处理路由，写接口

const Router = require('koa-router');

const router = new Router();

//安装路由的功能
app.use(router.routes())
app.use(router.allowedMethods());

router.get('/api/list',async (ctx,next) => {

    ctx.body = ctx.query;
})

router.post('/api/registry',async (ctx,next) => {
    //注册
    //用户名  密码
    //存到数据库里面
    ctx.body = ctx.request.body;
})

app.listen(3000,() => {
    console.log("服务器启动成功")
})